<template>
    <view>
        <view v-if="detail != null">
			<view class="padding-horizontal-main padding-top-main">
				<!-- 地址 -->
				<view v-if="detail.order_model == 0 || detail.order_model == 2" class="address bg-white padding-horizontal-main padding-top-main border-radius-main spacing-mb">
					<view class="address-base oh">
					    <text v-if="(detail.address_data.alias || null) != null" class="address-alias round br-main cr-main bg-white margin-right-sm">{{detail.address_data.alias}}</text>
					    <text>{{detail.address_data.name}}</text>
					    <text class="fr">{{detail.address_data.tel}}</text>
					</view>
					<view class="address-detail oh margin-bottom-main">
						<image class="icon fl" :src="groups_static_url+'mini/user-address.png'" mode="widthFix" />
						<view class="text fr">
							{{ detail.address_data.province_name }}{{ detail.address_data.city_name }}{{ detail.address_data.county_name }}{{ detail.address_data.address }}
							<text
								v-if="detail.order_model == 2 && (detail.address_data.lng || 0) > 0 && (detail.address_data.lat || 0) > 0"
								class="cr-666 br address-map-submit"
								@tap="address_map_event"
							>
								{{lang_info.order_detail_see_address_text}}
							</text>
						</view>
					</view>
					<view class="address-divider spacing-mb"></view>
				</view>
				<!-- 商品列表 -->
				<view class="goods bg-white padding-main border-radius-main spacing-mb">
				    <view class="br-b padding-bottom-main fw-b text-size">{{lang_info.order_detail_goods_title_text}}</view>
					<view class="goods bg-white spacing-mb">
						<view class="goods-item br-b-dashed oh" v-for="(item, index) in detail.items" :key="index">
							<navigator :url="'/pages/fcc/groups/detail/detail?goods_id=' + item.goods_id" hover-class="none">
								<image class="goods-image fl" :src="item.images" mode="aspectFill" />
								<view class="goods-base">
									<view class="goods-title multi-text">{{ item.title }}</view>
									<block v-if="item.spec != null">
										<view class="goods-attribute cr-888" v-for="(spec, index1) in item.spec" :key="index1">{{ spec.type }}:{{ spec.value }}</view>
									</block>
								</view>
								<view class="oh goods-price">
									<text class="sales-price">{{detail.currency_data.currency_symbol}}{{ item.price }}</text>
									<text v-if="item.original_price > 0" class="original-price">{{detail.currency_data.currency_symbol}}{{ item.original_price }}</text>
									<text class="buy-number">x{{ item.buy_number }}</text>
								</view>
							</navigator>
						</view>
						<view class="padding-top-main tr cr-base text-size"><text>{{detail.describe}}</text></view>
					</view>
				</view>

				<!-- 虚拟销售数据 -->
				<view v-if="detail.order_model == 3 && detail.pay_status == 1 && (detail.status == 3 || detail.status == 4)" class="site-fictitious panel-item padding-horizontal-main padding-top-main border-radius-main bg-white spacing-mb">
					<view class="br-b padding-bottom-main fw-b text-size">{{site_fictitious.title || lang_info.order_detail_key_info_text}}</view>
					<view class="panel-content oh padding-top-main">
						<view v-if="(site_fictitious.tips || null) != null" class="tips-value radius padding-main margin-bottom-main">
						    <mp-html :content="site_fictitious.tips" />
						</view>
						<view v-for="(item, index) in detail.items" :key="index" class="item br-b-dashed oh padding-bottom-main margin-bottom-main">
						    <image class="left-image br fl radius" :src="item.images" mode="aspectFill"></image>
						    <view class="right-value fr">
						        <view v-if="(item.spec_text || null) != null" class="text-grey padding-bottom-xs margin-bottom-xs br-b-f9 text-size-xs">{{item.spec_text}}</view>
						        <mp-html v-if="(item.fictitious_goods_value || null) != null" :content="item.fictitious_goods_value" />
						        <text v-else class="cr-grey">{{lang_info.order_detail_no_info_text}}</text>
						    </view>
						</view>
					</view>
				</view>

				<!-- 自提信息 -->
				<view v-if="detail.order_model == 2 && (detail.status == 2 || detail.status == 3) && (detail.extraction_data || null) != null" class="site-extraction panel-item padding-main border-radius-main bg-white spacing-mb">
					<view class="br-b padding-bottom-main fw-b text-size">{{lang_info.order_detail_pickup_info_text}}</view>
					<view class="panel-content oh padding-top-main">
						<view>
							<text>{{lang_info.order_detail_pickup_code_text}}：</text>
							<text class="code">{{ detail.extraction_data.code || lang_info.order_detail_not_pickup_text }}</text>
						</view>
						<image v-if="(detail.extraction_data.images || null) != null" class="br qrcode" :src="detail.extraction_data.images" mode="aspectFill" />
					</view>
				</view>

				<!-- 订单基础数据 -->
				<view v-if="detail_list.length > 0" class="panel-item padding-main border-radius-main bg-white spacing-mb">
					<view class="br-b padding-bottom-main fw-b text-size">{{lang_info.order_detail_order_info_text}}</view>
					<view class="panel-content oh">
						<view class="item br-b oh" v-for="(item, index) in detail_list" :key="index">
							<view class="title fl">{{ item.name }}</view>

							<view class="content cr-888 fl br-l">{{ item.value }}</view>
						</view>
					</view>
				</view>

				<!-- 扩展数据 -->
				<view v-if="extension_data.length > 0" class="panel-item padding-main border-radius-main bg-white spacing-mb">
					<view class="br-b padding-bottom-main fw-b text-size">{{lang_info.order_detail_ext_data_text}}</view>
					<view class="panel-content oh">
						<view class="item br-b oh" v-for="(item, index) in extension_data" :key="index">
							<text class="title">{{ item.name }}</text>

							<text class="content cr-888 br-l">{{ item.tips }}</text>
						</view>
					</view>
				</view>
			</view>

            <component-bottom-line :propStatus="data_bottom_line_status" :propMsg="lang_info.data_bottom_line_msg"></component-bottom-line>
        </view>

        <view v-if="detail == null">
            <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
        </view>
    </view>
</template>

<script>
import componentQuickNav from "@/components/quick-nav/quick-nav";
import componentBadge from '@/components/badge/badge';
import componentNoData from "@/components/no-data/no-data";
import componentBottomLine from "@/components/bottom-line/bottom-line";
import componentOnlineService from "@/components/online-service/online-service";
import { groups_base_info } from '@/pages/fcc/groups/public/common.js';
const app = getApp();
var groups_static_url = app.globalData.get_static_url('groups', true);
var common_static_url = app.globalData.get_static_url('common');
export default {
	components: {
		componentQuickNav,
	    componentBadge,
		componentNoData,
		componentBottomLine,
		componentOnlineService
	},
    data() {
        return {
            currency_symbol: app.globalData.currency_symbol(),
			groups_static_url: groups_static_url,
			common_static_url: common_static_url,
            params: null,
            data_list_loding_status: 1,
            data_list_loding_msg:'',
            data_bottom_line_status: false,
            detail: null,
            detail_list: [],
            extension_data: [],
            site_fictitious: null,
            team_user_list: [],
            alias: '',
            name: '',
            tel: '',
            lng: '',
            lat: '',
            code: '',
            images: '',
			// 多语言
			lang_info:{},
        };
    },
    onLoad(params) {
        //params['id'] = 5;
        this.setData({
            params: params
        });
        this.init();
    },
    onShow() {
		this.init_config();
		
        uni.setNavigationBarTitle({
            title: ''
        });
    },
    // 下拉刷新
    onPullDownRefresh() {
        this.init();
    },
    methods: {
		// 初始化配置
		init_config(status) {
		    if ((status || false) == true) {
				this.setData({
				    currency_symbol: app.globalData.get_config('currency_symbol'),
				    common_app_is_online_service: app.globalData.get_config('config.common_app_is_online_service'),
				});
		    } else {
		        app.globalData.is_config(this, 'init_config');
		    }
		},
		// 开始
		init(){
			groups_base_info()
			.then(data=>{
				this.init_before(data)
				.then(()=>{
					this.init_real()
				});
			});
		},
		// 设置本页参数
		init_before(data){
			var self = this;
			return new Promise((resolve, reject) => {
				self.setData({
					lang_info:data,
				});
				uni.setNavigationBarTitle({
				    title: data.order_detail_page_title
				});
				resolve();
			});
		},
		// 真正获取数据
        init_real() {
            var self = this;
            uni.showLoading({
                title: this.lang_info.loading_tips
            });
            this.setData({
                data_list_loding_status: 1
            });
            uni.request({
                url: app.globalData.get_request_url('OrderDetail', 'index', 'groups'),
                method: 'POST',
                data: {
                    id: this.params.id
                },
                dataType: 'json',
                success: (res) => {console.log(res);
                    uni.hideLoading();
                    uni.stopPullDownRefresh();

                    if (res.data.code == 0) {
                        var data = res.data.data;
						var temp_detail_data_list = self.lang_info.order_detail_data_list_array || [];
						if(temp_detail_data_list.length > 0){
							for (var i in temp_detail_data_list) {
								if(temp_detail_data_list[i]['value'] == 'payment_name'){
									temp_detail_data_list[i]['value'] = (data.data.payment_name || '') + ((data.data.is_under_line_text || null) == null ? '' : '（' + data.data.is_under_line_text + '）');
								}else{
									temp_detail_data_list[i]['value'] = ((data.data[temp_detail_data_list[i]['value']] || null) != null) ? data.data[temp_detail_data_list[i]['value']] : '';
								}
							}
						}
                        self.setData({
                            detail: data.data,
                            team_user_list: data.data.teamusers,
                            detail_list:temp_detail_data_list, 
                            extension_data: data.data.extension_data || [],
                            site_fictitious: data.site_fictitious || null,
                            data_list_loding_status: 3,
                            data_bottom_line_status: true,
                            data_list_loding_msg: ''
                        });
                    } else {
                        self.setData({
                            data_list_loding_status: 2,
                            data_bottom_line_status: false,
                            data_list_loding_msg: res.data.msg
                        });

                        if (app.globalData.is_login_check(res.data, self, 'init')) {
                            app.globalData.showToast(res.data.msg);
                        }
                    }
                },
                fail: () => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    self.setData({
                        data_list_loding_status: 2,
                        data_bottom_line_status: false,
                        data_list_loding_msg: this.lang_info.request_data_error_tips
                    });
                    app.globalData.showToast(this.lang_info.request_data_error_tips);
                }
            });
        },

        // 地图查看
        address_map_event(e) {
            if ((this.detail.address_data || null) == null) {
                app.globalData.showToast(this.lang_info.order_detail_address_wrong_tips);
                return false;
            }

            var ads = this.detail.address_data;
            var lng = parseFloat(ads.lng || 0);
            var lat = parseFloat(ads.lat || 0);

            if (lng <= 0 || lat <= 0) {
                app.globalData.showToast(this.lang_info.order_detail_lnglat_wrong_tips);
                return false;
            }

            uni.openLocation({
                latitude: lat,
                longitude: lng,
                scale: 18,
                name: ads.alias || '',
                address: (ads.province_name || '') + (ads.city_name || '') + (ads.county_name || '') + (ads.address || '')
            });
        }
    }
};
</script>
<style>
@import './orderdetail.css';
</style>
